home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / strdup.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  1KB  |  65 lines

  1. /*****************************************************************************
  2.   FILE           : strdup.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : System V Library Function strdup.
  7.   NOTES          : The strdup function is missing in the ULTRIX-32 operating system
  8.                     environment.
  9.  
  10.   AUTHOR         : Niels Mache
  11.   DATE           : 30.07.90
  12.  
  13.   CHANGED BY     : Sven Doering
  14.   IDENTIFICATION : @(#)strdup.c    1.11 3/15/94
  15.   SCCS VERSION   : 1.11
  16.   LAST CHANGE    : 3/15/94
  17.  
  18.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  19.  
  20. ******************************************************************************/
  21.  
  22. #ifndef ultrix
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <memory.h>
  26.  
  27. #ifndef strdup
  28. #define  strdup  bsd_strdup
  29. #endif
  30.  
  31. #else
  32.  
  33. #ifdef ultrix
  34.    /* DEC's pseudo ansi C-compiler doesn't understand const  */
  35. #  define const
  36. #endif
  37.  
  38. #include <stdlib.h>
  39. #include <sys/types.h>
  40. #include <stddef.h>
  41. #include <string.h>
  42. #include <memory.h>
  43.  
  44. #include "strdup.ph"
  45.  
  46. char *strdup(const char *str )
  47. {
  48.     int len;
  49.     char *copy;
  50.  
  51.         len = strlen( str ) + 1;
  52. #ifdef  __BORLANDC__
  53.         if (!(copy = malloc((size_t)len)))
  54.                 return((char *)NULL);
  55.         memcpy(copy, str, (size_t)len);
  56. #else
  57.     if (!(copy = malloc((unsigned int)len)))
  58.                 return((char *)NULL);
  59.     bcopy(str, copy, len);
  60. #endif
  61.     return(copy);
  62. }
  63.  
  64. #endif
  65.